import 'package:flutter/material.dart';

class StateFulCase extends StatefulWidget {
  const StateFulCase({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  // ignore: library_private_types_in_public_api
  _StateFulCaseState createState() => _StateFulCaseState();
}

class _StateFulCaseState extends State<StateFulCase> {
  int count = 0;

  @override
  Widget build(BuildContext context) {
    return Container(
        child: Column(
      children: [
        Text(widget.title, style: TextStyle(fontSize: 40)),
        Row(
          children: [
            ElevatedButton(
                onPressed: () {
                  // 必须把更新数据放在setState的回调函数中
                  setState(() {
                    count--;
                  });
                },
                child: Text("-")),
            Text(
              count.toString(),
              style: TextStyle(fontSize: 40),
            ),
            ElevatedButton(
                onPressed: () {
                  setState(() {
                    count++;
                  });
                },
                child: Text("+"))
          ],
        ),
      ],
    ));
  }
}
